import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import loadRoutes from './routes/index.js';
import errorHandler from './middleware/errorHandler.js';
import dotenv from 'dotenv';
import cors from '@koa/cors';
dotenv.config();

const app = new Koa();

// 应用中间件
app.use(errorHandler());
app.use(bodyParser());
// 跨域
app.use(cors());
// 加载路由
const router = loadRoutes();
app.use(router.routes()).use(router.allowedMethods());

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`🚀 Server running on http://localhost:${PORT}`);
});
